package com.gt.quality.system.mapper;

import com.gt.quality.config.handler.EasyBaseMapper;
import com.gt.quality.system.entity.SysRole;
import com.gt.quality.system.entity.SysUserRole;
import com.gt.quality.system.entity.dto.SysUserDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户和角色关联表(SysUserRole)表数据库访问层
 *
 * @author makejava
 * @since 2026-11-25 16:30:08
 */
@Mapper
public interface SysUserRoleMapper extends EasyBaseMapper<SysUserRole> {

    String QUERY_FOR_USER_ID_SQL = "select * from sys_role where role_id in (select role_id from sys_user_role where user_id = #{userId})";

    String QUERY_FOR_ROLE_ID_SQL = "select * from sys_user where user_id in (select user_id from sys_user_role where role_id = #{roleId})";

    /**
     * 根据用户id查询角色
     *
     * @param userId userId
     */
    @Select(QUERY_FOR_USER_ID_SQL)
    List<SysRole> queryForUserId(@Param("userId") String userId);

    /**
     * 根据角色Id查询用户
     *
     * @param roleId roleId
     */
    @Select(QUERY_FOR_ROLE_ID_SQL)
    List<SysUserDTO> queryForRoleId(String roleId);
}

